/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: config头文件
 */
#ifndef UTIL_H
#define UTIL_H

#include <opencv2/core/core.hpp>
#include <opencv2/core/utils/filesystem.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <vector>
#include <iostream>
#include <chrono>
#include <ctime>
#include <sstream>
#include <iomanip>
#include <string>
#include <sys/stat.h>
#include "yaml/haf_yaml.h"

std::string CurrentTimeAndDate();

int32_t GetFilesBySort(std::string &path, std::vector<std::string> &files, std::string suffix);
time_t ConvertTimeStr2TimeStamp(std::string timeStr);

class FuncTimeMeasure {
public:
    explicit FuncTimeMeasure(std::string &&descrip);
    ~FuncTimeMeasure();

private:
    std::string description;
    std::chrono::time_point<std::chrono::steady_clock> start {};
    std::chrono::time_point<std::chrono::steady_clock> end {};
};

struct Config {
    std::string dir { "" };
    int32_t instanceId { 0 };
    int32_t width { 0 };
    int32_t height { 0 };
};

class ConfigManage {
public:
    ConfigManage() = default;
    ~ConfigManage() = default;
    explicit ConfigManage(std::string configFile) : file(configFile) {}
    void Parse();
    std::vector<Config> GetConfig();
    void Show();
    bool CheckConfig();
    inline static bool FileExist(const std::string &name)
    {
        struct stat buffer;
        return (stat(name.c_str(), &buffer) == 0);
    }
    int gRet = -1;

private:
    std::string file { "image_config.yaml" };
    std::vector<Config> configs {};
};
#endif // UTIL_H
